package com.ajk.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ajk.server.dao.TestQuestionAnswerMapper;
import com.ajk.server.model.TestQuestionAnswer;
import com.ajk.server.model.query.TestQuestionAnswerQuery;
import com.ajk.server.service.TestQuestionAnswerService;

/**
 * 测试题答案  <br>
 * t_test_question_answer <br>
 * v1.0 2016-05-01
 */
 @Service
 public class TestQuestionAnswerServiceImpl implements TestQuestionAnswerService {
	
	private static final Logger logger = LoggerFactory.getLogger(TestQuestionAnswerServiceImpl.class);
	
	@Autowired
	private TestQuestionAnswerMapper testQuestionAnswerMapper;
	
	/**
 	*根据ID删除 测试题答案
 	*/
 	@Override
 	public Integer deleteTestQuestionAnswerById(Integer id){
 		return testQuestionAnswerMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 测试题答案
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertTestQuestionAnswer(List<? extends TestQuestionAnswer> testQuestionAnswers){
		Integer count = testQuestionAnswerMapper.batchInsert(testQuestionAnswers);
		return count;
 	}
 	/**
 	*新增 测试题答案
 	*/
 	@Override
 	@Transactional
 	public Integer insertTestQuestionAnswer(TestQuestionAnswer domain){
		Integer id = testQuestionAnswerMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 测试题答案
 	*/
 	@Override
 	@Transactional
 	public Integer updateTestQuestionAnswer(TestQuestionAnswer domain){
		Integer count = testQuestionAnswerMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 测试题答案
 	*/
 	public TestQuestionAnswer findTestQuestionAnswerById(Integer id){
 		TestQuestionAnswer result = testQuestionAnswerMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 测试题答案
 	*/
	public List<TestQuestionAnswer> findTestQuestionAnswerByQuery(TestQuestionAnswerQuery query){
		query.dealWith();
		List<TestQuestionAnswer> result = testQuestionAnswerMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TestQuestionAnswer testQuestionAnswer : result) {
				testQuestionAnswer.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countTestQuestionAnswerByQuery(TestQuestionAnswerQuery query){
 		query.dealWith();
 		Integer result = testQuestionAnswerMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<TestQuestionAnswer> findTestQuestionAnswerByIds(List<Integer> ids){
 		List<TestQuestionAnswer> result = testQuestionAnswerMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TestQuestionAnswer testQuestionAnswer : result) {
				testQuestionAnswer.dealWith();
			}
		}
		return result;
 	}
 	
}	